home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr46 / acm_rand.zip / RAND16.C next >
C/C++ Source or Header  |  1993-01-16  |  767b  |  43 lines

  1. #include "rand16.h"
  2.  
  3. int _s16r1 = 0;
  4. int _s16r2 = 0;
  5. int _s16r3 = 0;
  6.  
  7. void srand16(int s1, int s2, int s3)
  8. {
  9.     _s16r1 = (s1 % 32362) + 1;
  10.     _s16r2 = (s2 % 31726) + 1;
  11.     _s16r3 = (s3 % 31656) + 1;
  12. }
  13.  
  14. int rand16(void)
  15. {
  16.     register int z, k;
  17.  
  18.     k = _s16r1 / 206;
  19.     _s16r1 = (157 * (_s16r1 - (k * 206))) - (k * 21);
  20.     if (_s16r1 < 0)
  21.         _s16r1 += 32363;
  22.     k = _s16r2 / 217;
  23.     _s16r2 = (146 * (_s16r2 - (k * 217))) - (k * 45);
  24.     if (_s16r2 < 0)
  25.         _s16r2 += 31657;
  26.     k = _s16r3 / 222;
  27.     _s16r3 = (142 * (_s16r3 - (k * 222))) - (k * 133);
  28.     if (_s16r3 < 0)
  29.         _s16r3 += 31657;
  30.     z = _s16r1 - _s16r2;
  31.     if (z > 706)
  32.         z -= 32362;
  33.     z += _s16r3;
  34.     if (z < 1)
  35.         z += 32362;
  36.     return z;
  37. }
  38.  
  39. double rand16u(void)
  40. {
  41.     return ((double) rand16() * 3.0899e-5);
  42. }
  43.